package org.apache.lucene.analysis.compound.morphology;

import org.apache.lucene.analysis.util.CharArraySet;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class ayAdi  implements sandhi {
	public boolean isInDict(CharArraySet dict, String word) {
		char [] warr = word.toCharArray();
		return dict.contains(warr, 0, word.length());
	}
	
	public String splitDevanagari(String word,  CharArraySet dict){
		String a = null;
		
		for(int i = 0; i < word.length(); i++){
			
			if((i+1 < word.length() ) && word.substring(i, i+2).equals("ये")){
				String w1 = word.substring(0,i) + "े";
				String ss = "";
				if (i+2 <word.length())
					ss = word.substring(i+2);
				String w2 = "ए"+ ss;
				if(isInDict(dict, w1) && isInDict(dict, w2)){
					a = w1 + " " + w2;
					return a;
				}//end if
			}//end else if
			else if((i+1 < word.length() ) && word.substring(i, i+2).equals("ाय")){
				String w1 = word.substring(0, i) + "ै";
				String ss = "";
				if (i+2 <word.length())
					ss = word.substring(i+2);
				String w2 = "अ" + ss;
				if(isInDict(dict, w1) && isInDict(dict, w2)){
					a = w1 + " " + w2;
					return a;
				}//end if
			}//end else if
			else if(word.substring(i, i+1).equals("य")){
				String w1 = word.substring(0, i) + "े";
				String ss = "";
				if (i+1 <word.length())
					ss = word.substring(i+1);
				String w2 = "अ" + ss;
				if(isInDict(dict, w1) && isInDict(dict, w2)){
					a = w1 + " " + w2;
					return a;
				}//end if
			}//end if
			else if((i+1 < word.length() ) && word.substring(i, i+2).equals("वे")){
				String w1 = word.substring(0, i) + "ो";
				String ss = "";
				if (i+2 <word.length())
					ss = word.substring(i+2);
				String w2 = ss + "ए";
				if(isInDict(dict, w1) && isInDict(dict, w2)){
					a = w1 + " " + w2;
					return a;
				}//end if
			}//end else if
			
			else if((i+2 < word.length() ) && word.substring(i, i+3).equals("ावु")){
				String w1 = word.substring(0, i) + "ौ";
				String ss = "";
				if (i+3 <word.length())
					ss = word.substring(i+3);
				String w2 = "उ" + ss;
				if(isInDict(dict, w1) && isInDict(dict, w2)){
					a = w1 + " " + w2;
					return a;
				}//end if
			}//end else if
			
			else if((i+2 < word.length() ) && word.substring(i, i+3).equals("ावे")){
				String w1 = word.substring(0, i) + "ौ";
				String ss = "";
				if (i+3 <word.length())
					ss = word.substring(i+3);
				String w2 = "ए" + ss;
				if(isInDict(dict, w1) && isInDict(dict, w2)){
					a = w1 + " " + w2;
					return a;
				}//end if
			}//end else if
			else if((i+1 < word.length() ) && word.substring(i, i+2).equals("ाव")){
				String w1 = word.substring(0, i) + "ौ";
				String ss = "";
				if (i+2 <word.length())
					ss = word.substring(i+2);
				String w2 = "अ" + ss;
				if(isInDict(dict, w1) && isInDict(dict, w2)){
					a = w1 + " " + w2;
					return a;
				}//end if
			}//end else if
			else if(word.substring(i, i+1).equals("व")){
				String w1 = word.substring(0, i) + "ो";
				String ss = "";
				if (i+1 <word.length())
					ss = word.substring(i+1);
				String w2 = "अ" + ss;
				if(isInDict(dict, w1) && isInDict(dict, w2)){
					a = w1 + " " + w2;
					return a;
				}//end if
			}//end else if
		}//end for
		return null;
	}//end method
	
	
		
	public String split(char[] wordArr, int len, CharArraySet dict){
		String word="";
		for (int i = 0; i < len; i++)
			word += wordArr[i];
		word = word.toLowerCase();
		String wd = splitDevanagari(word, dict);
		if (wd != null)
			return wd;

			for(int i = 0; i < word.length()-2; i++){
				if(word.substring(i, i+2).equals("ay")){
					String w1 = word.substring(0, i) + "e";
					String w2 = word.substring(i+2);
					if(isInDict(dict, w1) && isInDict(dict, w2)){
						String a = w1 + " " + w2;
						return a;
					}//end if
				}//end if
				else if(((i+3) <= word.length()) && word.substring(i, i+3).equals("aay")){
					String w1 = word.substring(0,i) + "ai";
					String w2 = word.substring(i+3);
					if(isInDict(dict, w1) && isInDict(dict, w2)){
						String a = w1 + " " + w2;
						return a;
					}//end if
				}//end else if
				else if(word.substring(i, i+2).equals("av")){
					String w1 = word.substring(0, i) + "o";
					String w2 = word.substring(i+2);
					if(isInDict(dict, w1) && isInDict(dict, w2)){
						String a = w1 + " " + w2;
						return a;
					}//end if
				}//end else if
				else if(((i+3) <= word.length()) && word.substring(i, i+3).equals("aav")){
					String w1 = word.substring(0, i) + "au";
					String w2 = word.substring(i+3);
					if(isInDict(dict, w1) && isInDict(dict, w2)){
						String a = w1 + " " + w2;
						return a;
					}//end if
				}//end else if
			}//end for
			 //return "Word doesn't contain sandhi.";
		return null;
		}//end method
	
}//end class
